﻿@namespace BootstrapBlazor.Components
@typeparam TValue
@inherits ButtonUploadBase<TValue>

@if (IsShowLabel)
{
    <BootstrapLabel required="@Required" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
}
<div @attributes="@AdditionalAttributes" class="@ClassString" id="@Id">
    <div class="@BodyClassString">
        @foreach (var item in GetUploadFiles())
        {
            <div @key="@item" class="@GetItemClassString(item)">
                <div class="upload-item-body">
                    @if (IsImage(item))
                    {
                        <img alt="prevUrl" src="@item.PrevUrl" />
                    }
                    else
                    {
                        <i class="@GetFileFormatClassString(item)"></i>
                    }
                </div>
                <div class="upload-item-size"><span>@GetFileName(item)</span> (@item.Size.ToFileSizeString())</div>
                <div class="upload-item-actions">
                    <div class="btn-group">
                        <button type="button" class="btn btn-sm btn-secondary" disabled="@GetDiabledString(item)" @onclick="() => OnClickZoom(item)" aria-label="zoom">
                            <i class="fa-solid fa-magnifying-glass-plus"></i>
                        </button>
                        @if(ShowDownloadButton)
                        {
                            <button type="button" class="btn btn-sm btn-secondary" disabled="@GetDiabledString(item)" @onclick="() => OnClickDownload(item)" aria-label="download">
                                <i class="fa-solid fa-download"></i>
                            </button>
                        }
                    </div>
                    <DynamicElement TagName="button" type="button" class="btn btn-sm btn-outline-danger"
                                    disabled="@GetDeleteButtonDiabledString(item)" aria-label="delete"
                                    TriggerClick="@(!IsDisabled)" OnClick="@(() => OnCardFileDelete(item))">
                        <i class="fa-regular fa-trash-can"></i>
                    </DynamicElement>
                </div>
                @if (GetShowProgress(item))
                {
                    <Progress Color="Color.Success" Height="4" Value="@item.ProgressPercent" />
                }
                <span class="upload-item-label">
                    <i class="fa-solid fa-check"></i>
                    <i class="fa-solid fa-xmark"></i>
                </span>
            </div>
        }
        @if (CanUpload)
        {
            <div class="@CardItemClass">
                <div class="upload-item-actions btn-browser">
                    @if (!IsDisabled)
                    {
                        <span class="upload-item-plus">
                            <i class="fa-solid fa-plus"></i>
                        </span>
                    }
                </div>
            </div>
        }
    </div>
    <InputFile AdditionalAttributes="@GetUploadAdditionalAttributes()" OnChange="OnFileChange" />

    @if (ShowPreviewList)
    {
        <ImagePreview PreviewList="PreviewList" />
    }
</div>
